<template>
  <t-table
    rowKey="id"
    size="small"
    :data="data"
    :columns="columns"
    hover
    :loading="dataLoading"
  >
    <template #thesisCount="{ row }">
      <t-link @click="clickToIndex('/cgzh/thesis/thesis-my','kjxm',row)" hover="color"
              theme="primary">{{ row.thesisCount }}
      </t-link>
    </template>
    <template #patentCount="{ row }">
      <t-link @click="clickToIndex('/cgzh/patent/patent-my','kjxm',row)" hover="color"
              theme="primary">{{ row.patentCount }}
      </t-link>
    </template>
    <template #awardsCount="{ row }">
      <t-link @click="clickToIndex('/cgzh/awards/awards-my','kjxm',row)" hover="color"
              theme="primary">{{ row.awardsCount }}
      </t-link>
    </template>
    <template #treatiseCount="{ row }">
      <t-link @click="clickToIndex('/cgzh/treatise/treatise-my','kjxm',row)" hover="color"
              theme="primary">{{ row.treatiseCount }}
      </t-link>
    </template>
    <template #softwareCopyrightCount="{ row }">
      <t-link @click="clickToIndex('/cgzh/copyright/copyright-my','kjxm',row)" hover="color"
              theme="primary">{{ row.softwareCopyrightCount }}
      </t-link>
    </template>
    <template #constructMethodCount="{ row }">
      <t-link @click="clickToIndex('/cgzh/gf/gf-my','kjxm',row)" hover="color"
              theme="primary">{{ row.constructMethodCount }}
      </t-link>
    </template>
    <template #performanceCount="{ row }">
      <t-link @click="clickToIndex('/cgzh/other/other-my','kjxm',row)" hover="color"
              theme="primary">{{ row.performanceCount }}
      </t-link>
    </template>
    <template #op="{ row }">

      <t-dropdown   trigger="click">
        <t-button size="small" variant="text" class="t-button-link">
          <t-icon name="add" slot="icon"/>
          成果录入
        </t-button>
        <t-dropdown-menu  slot="dropdown">
          <t-dropdown-item  @click="clickToApply(`/cgzh/other/thesis/thesis-apply/${Date.parse(new Date())}`,'kjxm', row)" ><t-button  size="small" variant="text" class="t-button-link">
            录入论文
          </t-button></t-dropdown-item>
          <t-dropdown-item @click="clickToApply(`/cgzh/other/treatise/treatise-apply/${Date.parse(new Date())}`,'kjxm', row)"> <t-button  size="small" variant="text" class="t-button-link">
            录入著作
          </t-button></t-dropdown-item>
          <t-dropdown-item @click="clickToApply(`/cgzh/other/patent/patent-apply/${Date.parse(new Date())}`,'kjxm', row)"> <t-button  size="small" variant="text" class="t-button-link">
            录入专利
          </t-button></t-dropdown-item>
          <t-dropdown-item  @click="clickToApply(`/cgzh/other/copyright/copyright-apply/${Date.parse(new Date())}`,'kjxm', row)"> <t-button  size="small" variant="text" class="t-button-link">
            录入软著
          </t-button></t-dropdown-item>
          <t-dropdown-item  @click="clickToApply(`/cgzh/other/awards/awards-apply/${Date.parse(new Date())}`,'kjxm', row)"> <t-button  size="small" variant="text" class="t-button-link">
            录入获奖
          </t-button></t-dropdown-item>
          <t-dropdown-item  @click="clickToApply(`/cgzh/other/gf/gf-apply/${Date.parse(new Date())}`,'kjxm', row)"> <t-button  size="small" variant="text" class="t-button-link">
            录入工法
          </t-button></t-dropdown-item>
          <t-dropdown-item  @click="clickToApply(`/cgzh/other/other/other-apply/${Date.parse(new Date())}`,'kjxm', row)"  > <t-button  size="small" variant="text" class="t-button-link">
            录入其他
          </t-button></t-dropdown-item>
        </t-dropdown-menu>
      </t-dropdown>
    </template>
  </t-table>
</template>

<script>
export default {
  name: "project-achievement",
  props: {
    objId: [String, Number],
  },
  data(){
    return {
      data: [],
      columns: [
        {
          colKey: "thesisCount",
          title: "论文个数",
          align: "center",
          width: 100
        },
        {
          colKey: "treatiseCount",
          title: "著作个数",
          align: "center",
          width: 100
        },
        {
          colKey: "patentCount",
          title: "专利个数",
          align: "center",
          width: 100
        },
        {
          colKey: "softwareCopyrightCount",
          title: "软著个数",
          align: "center",
          width: 100
        },
        {
          colKey: "awardsCount",
          title: "获奖个数",
          align: "center",
          width: 100
        },
        {
          colKey: "constructMethodCount",
          title: "工法个数",
          align: "center",
          fixed: 'right',
          width: 100
        },
        {
          colKey: "performanceCount",
          title: "其他个数",
          align: "center",
          width: 100
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 140,

        },
      ],
      dataLoading: false,
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler(val) {
        if (val) {
          this.getList(val);
        }
      }
    },
  },
  methods:{
    clickToIndex(path, serviceCode, row) {
      const query = {
        serviceCode,
        projectName:row.projectName,
        businessId: row.id
      }
      this.$router.push({
        path,
        query
      })
    },
    getList(){
      // 根据项目Id 查询我的项目
      this.$api.kjxm.project.myAchievementList({id:this.objId}).then(response => {
        this.data = response.rows;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    clickToApply(path, serviceCode, row){
      // 根据 serviceCode 获取 service 信息
      this.$api.system.subsystem.getServiceByCode(serviceCode).then(res => {
        this.$router.push({
          path,
          query: {
            serviceCode,
            serviceId: res.data.id,
            serviceName: res.data.serviceName,
            businessName:row.projectName,
            businessId: row.id
          }
        });
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
  }
}
</script>

<style scoped>

</style>
